<?php
/*
 * @Created by: wangchengcheng
 * @Author: wangchengcheng
 * @Date: 2020-01-03 17:34:28
 * @LastEditors  : wangchengcheng
 * @LastEditTime : 2020-01-06 22:48:32
 */

namespace App\Models;

/**
 * App\Models\ArticleTag
 *
 * @property                            int  $article_id 文章id
 * @property                            int  $tag_id 标签id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null                     $deleted_at
 */
class ArticleTag extends base
{
    public $timestamps = true;
    /**
     * 为文章批量插入标签
     * 
     * @return bool
     */
    public function addTagIds(int $article_id, array $tag_ids)
    {
        //组合批量插入的数据
        $data = array_map(function($tag) use ($article_id){
            return [
                'article_id' => $article_id,
                'tag_id'     => $tag,
                'created_at' => date('Y-m-d H:i:s'),
            ];
        }, $tag_ids);

        return $this->insert($data);
    }
} 
